<?php
/**
 * WebProduction Shop (wpshop)
 * @copyright (C) 2011-2012 WebProduction (tm) <webproduction.com.ua>
 *
 * This program is commercial software; you cannot redistribute it and/or
 * modify.
 */

/**
 * @copyright WebProduction
 * @package Shop
 */
class Shop_ContentFieldGravatar extends Forms_ContentField {

    public function __construct($keyValue) {
        parent::__construct($keyValue);

        $this->getContentView()->setFileHTML(dirname(__FILE__).'/'.__CLASS__.'.html');
    }

    public function renderView(Forms_ContentTable $table, $rowIndex, $cellsArray) {
        $assigns = array();
        $keyPrimary = $table->getDataSource()->getFieldPrimary()->getKey();

        $id = @$cellsArray[$keyPrimary];
        if ($id) {
            try {
                $user = BC::Get()->getUserService()->getUserByID($id);
                $gravatar = $user->makeImageGravatar(32);

                $assigns['gravatar'] = $gravatar;
            } catch (Exception $e) {

            }
        }

        return $this->getContentView()->render($assigns);
    }

}